home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / s0ftpj / pippa_v1.txt < prev    next >
Encoding:
Text File  |  2000-12-17  |  12.8 KB  |  357 lines

  1.                           
  2.                           pippa, a network datapipe
  3.                           by b0z0/iKX, Padania 1998
  4.  
  5.  
  6.  
  7. What is pippa?
  8. --------------
  9.  pippa is a small network datapipe written in Perl. Basically pippa's work
  10. is to redirect a network connection from one site to another, thus hiding
  11. the identity of the real connection originator and exposing just the host
  12. where the datapipe is running.
  13.  
  14.  
  15. What should I do with it?
  16. -------------------------
  17.  Well, pretty obviously, when you would like to hide (of course this
  18. method of hiding yourself is just relatively secure) your connection from
  19. some third host making just the host running the datapipe to be exposed.
  20. This can be very useful when you don't want that other users see your 
  21. provider's host on irc, when you would like to remain anonymous when
  22. sending mail, if you would like to conserve your privacy while hacking
  23. into other people's site or when you would like to make some packets to
  24. cross your country's border and then return in your country thus making
  25. some more problems to the local lawyers ;)
  26.  
  27.  
  28. How it works?
  29. -------------
  30.  Simple, it just gets the packets it receives in input (from some incoming
  31. connection) and send them to some desired target machine. So, with a small
  32. ascii art:
  33.  
  34.                   /-----\        /-----\        /-----\
  35.                   |  A  |------->|  B  |------->|  C  |
  36.                   | 789 |<-------| 456 |<-------| 678 |
  37.                   \-----/        \-----/        \-----/
  38.  
  39.  You are host A, starting from port 789. On the host B pippa is supposed
  40. to run on port 456. You'll connect to the host B on port 456. Then you
  41. will be able to send (in either interactive or noninteractive mode) some
  42. data to the port 678 of the host C. Of course the host C will just think
  43. that someone is connecting from host B and won't care at all about host A.
  44.  
  45.  
  46. What has pippa to offer?
  47. ------------------------
  48.  pippa is a quite small network datapipe written in Perl, so it should be
  49. very easy to use on a lot of different platforms (mainly every
  50. system that has Perl installed, so all kind of unixes and windoze
  51. nt too) without the need of compiling or something (except some variables
  52. should have to be changed, but this changes too are easy to do and well
  53. documented in the system's include files).
  54.  pippa is quite versatile, it can run in noninteractive mode (so it should
  55. just feed all the packets from the input to the desired fixed target) or
  56. in interactive mode (so you will have a small command prompt where you'll
  57. be able to select to which host/port to connect and so on), so it can be
  58. used for many puroposes without the need to be restarted each time.
  59.  two or more interactive or noninteractive pippas can be used in chain
  60. thus making your work choices of the destination and such very easy
  61. without the need of restarting the datapipe or something. 
  62.  pippa has some small logging options.
  63.  
  64.  
  65. Starting pippa
  66. --------------
  67.  Start pippa with a '-h 1' parameter and you'll get a list of the possible
  68. pippa command line options. The cmdline options are selfexplanatory, so
  69. here come just a few samples of starting pippa. 
  70.  
  71.    pippa -p 3456 &
  72. pippa will wait on port 3456 in interactive mode, so when someone will log
  73. on that port it will send the prompt 'pippa>' and wait for commands.
  74.  
  75.    pippa -p 3456 -b 1 &
  76. same as before, but in this case pippa will bind itself on all the
  77. adresses of the machine where pippa was started (while without the -b 1 it
  78. will bind just as the adress that results as the output of the hostname
  79. program).
  80.  
  81.    pippa -d 1 2>&1 > .pippalog &
  82. pippa will wait on the default 2345 port in interactive mode. All the
  83. connections to pippa and all the issued commands will be logged and
  84. everything redirected in the .pippalog file. (you should have to change
  85. the STDERR redirection to STDOUT according to the shell you're using)
  86.  
  87.    pippa -p 3456 -F 1 -P 6667 -H irc.ais.net &
  88. pippa will wait for connections on port 3456 and will redirect any
  89. incoming connection to the port 6667 of the server irc.ais.net. This is an
  90. easy example of the use of pippa for irc spoofing, since the irc server
  91. and the other irc users will actually see the user as if it is connecting
  92. from the datapipe host. People with a brain should notice that you have to
  93. pay attention at some IRC client things such as DCC, when your real
  94. connection could be revealed anyway.
  95.  
  96.    pippa -F 1 -P 3456 -H fakeirc.com -I 'open irc.ais.net 6667' &
  97. pippa will wait on the default 2345 port for connection in non interactive
  98. mode. Each time someone will connect pippa will redirect the connection to
  99. the fakeirc.com at port 3456 and will send as the first line the 'open
  100. irc.ais.net 6667'. This is very useful when chaining two or more pippa
  101. datapipes. Infact if pippa is running in interactive mode it should be a
  102. bit shitty to use it with and irc client. So you should just install a
  103. datapipe on your own host that will just pipe all the data to the
  104. interactive pipe outside but will additionally initialize it for use with
  105. IRC (this is, will send the string to open the connection to an IRC
  106. server). This way you can use an interactive datapipe as an uninteractive
  107. pipe, since there isn't any prob to install one pipe more on your local
  108. system. As you can see there will be some output (the pippa> prompt and
  109. the connecting status strings) sent to the second datapipe from the first
  110. uninteractive one when it will execute the initialization string, but IRC
  111. clients will treat this just as garbage and will work ok anyway, so don't
  112. worry. 
  113.  
  114.  
  115. Using pippa in interactive mode
  116. -------------------------------
  117.  There isn't too much to say. By writing help at the prompt you'll get the
  118. command list. To connect to a site just write open <host> <port> where
  119. port can be the port number or the port name (from /etc/services). And
  120. then you can do what you want to.
  121.  There is also a ping command that relies on the ping program of the host
  122. running pippa. This will just ping the desired site and send ya the output
  123. in case you would like to check if the site is up and running.
  124.  
  125.  
  126. Known problems
  127. --------------
  128.  There is one known problem with this datapipe that wasn't corrected
  129. because the datapipe should have been written with a quite different
  130. approach from the very beginning to leave out this problem.
  131.  Basically when you connect to the telnet (23) port of a site running 
  132. pippa in interactive mode with a telnet client, when you logout the telnet
  133. client should (some does, some don't) have strange behaviours, since the
  134. telnet client remains in a quite strange state for some commands the
  135. destination daemon sends. So in some cases you should just go to the
  136. telnet client command line (using the escape character, usually ^]) and
  137. then reput it in line mode (mode line), but more likely you'll have to
  138. exit from the telnet client and then reconnect to the datapipe once again 
  139. for the next work. I hope this won't cause too much probs to ya.
  140.  Anyway for a note, this should be corrected by rewriting all the pippa
  141. input routines with a char-by-char input strategy (so it should
  142. drastically change), by monitoring the finishing telnet sequences at the
  143. end of the connection (too lazy to write this) or even by restoring all
  144. the telnet settings at the end of the session (too much rfcs to browse :) 
  145. ).
  146.  
  147. The code
  148. --------
  149.  Here it comes. Just change the path to the perl interpreter (or delete it
  150. if ya are running it under windozes) and change the socket constants if
  151. needed.
  152.  
  153.  
  154. --------------------->8----------[cut here]----------8<----------------------
  155. #!/usr/bin/perl
  156.  
  157. #
  158. # pippa, a network datapipe
  159. # by b0z0/iKX, Padania april 1998
  160. #
  161. # start it with the -h 1 option to get some help
  162. # write help at the pippa> prompt to get some help on the interactive mode
  163. #
  164.  
  165. # Tested under Linux with Perl 5.004
  166. # Tested under Digital Unix 4.0 with Perl 5.004
  167. # Tested under SunOS 5 with Perl 5.003
  168.  
  169. use Socket;
  170.  
  171. require "getopt.pl";
  172.  
  173. $SIG{'CHLD'}='IGNORE';
  174.  
  175. &Getopt('hpdbPHFI');        # Get some needed cmdline options
  176. $help=$opt_h;
  177. $port=$opt_p;
  178. $bindany=$opt_b;
  179. $debug=$opt_d;
  180. $destport=$opt_P;
  181. $desthost=$opt_H;
  182. $nonint=$opt_F;
  183. $initstr=$opt_I;
  184.  
  185. $port=2345 unless $port;    # Some defaults
  186. $destport=25 unless $destport;
  187. $desthost="127.0.0.1" unless $desthost;
  188.  
  189. if ($help) {
  190.  print "pippa usage:\n";
  191.  print "  -h 1           = help\n";
  192.  print "  -p xxxx        = run pippa on port xxxx\n";
  193.  print "  -d 1           = output debug infos\n";
  194.  print "  -b 1           = bind to any adress of the machine\n";
  195.  print "  -F 1           = non interactive mode, just pipe to -H -P\n";
  196.  print "     -P xxxx     = fix destination port to xxxx\n";
  197.  print "     -H xxxx     = fix destination host to xxxx\n";
  198.  print "     -I xxxxx    = send string xxxxx at beginning\n\n";
  199.  exit();
  200. }
  201.  
  202. $AF_INET=2;
  203.  
  204. # This should very probably change for some operating systems
  205. # Check the socket include files (sys/socket.h) for this value
  206.  
  207. $SOCK_STREAM=1;        # should be 2 for SunOS
  208.  
  209. $sockaddr='S n a4 x8';
  210.  
  211. chop($hostname=`hostname`);    # Infos on machine running pippa
  212. ($name,$aliases,$type,$len,$thisaddr)= gethostbyname($hostname) if $hostname;
  213.  
  214.  
  215. ($name,$aliases,$proto)=getprotobyname('tcp');
  216. if($port !~ /^\d+$/) {
  217.    ($name, $aliases, $port) = getservbyname($port,'tcp');
  218. }
  219.  
  220. $thisaddr=INADDR_ANY if ($bindany or !($thisaddr));       
  221.                                # bind to any adress avaiable
  222.  
  223. $this= pack($sockaddr,$AF_INET,$port,$thisaddr);
  224. select(NS); $|=1; select(STDOUT); $|=1;
  225.  
  226. socket(S,$AF_INET, $SOCK_STREAM, $proto) || die "socket: $!";
  227. bind(S,$this) || die "bind: $!";
  228. listen(S,5) || die "connect: $!";    # Stay on port and wait for conns
  229.  
  230. select(S); $|=1; select(STDOUT);
  231.  
  232. for ($con=1;;$con++) {
  233.   ($addr=accept(NS,S)) || die $!;
  234.   if (($child=fork())==0) {
  235.     ($af,$port,$inetaddr)=unpack($sockaddr,$addr);
  236.     @inetaddr=unpack('C4',$inetaddr);
  237.  
  238.     @datetime=localtime(time);
  239.     print "$datetime[3]/$datetime[4]/$datetime[5] " if $debug; 
  240.     print "$datetime[2]:$datetime[1]:$datetime[0] from " if $debug;
  241.     print "$inetaddr[0].$inetaddr[1].$inetaddr[2].$inetaddr[3]" if $debug;
  242.     print ":$port connection nr=$con\n" if $debug;
  243.         
  244.     print NS "pippa> " if !($nonint);
  245.     select(S); $|=1; select(STDOUT); $|=1;
  246.  
  247.     doopen() if $nonint;
  248.     exit() if $nonint;
  249.     while (<NS>) {
  250.       print STDOUT "nr=$con command: $_" if ($debug and !($nonint));
  251.       @command=split(' ',$_);
  252.       $_=$command[0];
  253.       CMDLOOP: {
  254.         if (/^open$/) {
  255.               doopen();
  256.               last CMDLOOP;
  257.           }
  258.  
  259.         if (/^ping$/) {
  260.           if (!($command[1]) or ($command[2])) {
  261.              print NS "bad ping params\n";
  262.           }
  263.           elsif (!($command[1] =~ /^(\w+\.*)+$/)) {
  264.              print NS "nice params\n";
  265.           }
  266.           else {
  267.              open(SAVEOUT,">&STDOUT");
  268.              open(SAVEERR,">&STDERR");
  269.  
  270.              open(STDOUT,">&NS");
  271.              open(STDERR,">&STDOUT");
  272.              system("ping -c 3 $command[1]");
  273.              close(STDOUT);
  274.              close(STDERR);
  275.  
  276.              open(STDOUT,">&SAVEOUT");
  277.              open(STDERR,">&SAVEERR");
  278.           }
  279.           last CMDLOOP;
  280.         }
  281.  
  282.         if (/^help$/) {
  283.           print NS "avaiable commands:\n";
  284.           print NS "  open <host> <port>  : connect to <host> at <port>\n";
  285.           print NS "  ping <host>         : ping <host> three times\n";
  286.           print NS "  help                : this shit\n";
  287.           print NS "  quit                : bail out\n";
  288.           print NS "  exit                : bail out\n\n";
  289.           last CMDLOOP;
  290.         }
  291.  
  292.         if (/^$/) { last CMDLOOP; }
  293.  
  294.         if ((/^quit$/) or (/^exit$/)) {
  295.           close(NS);
  296.           exit();
  297.         }
  298.        print NS "bad command\n";
  299.       }
  300.     print NS "pippa> " if !($nonint);
  301.     exit() if $nonint;
  302.     }
  303.   close(NS);
  304.   exit();
  305.  }
  306. close(NS);
  307. }
  308.  
  309.  
  310. sub doopen {
  311.  DOOPEN: {
  312.    $outta= pack($sockaddr,$AF_INET,0,$thisaddr);
  313.    socket(OUT,$AF_INET, $SOCK_STREAM, $proto) || die "socket: $!";
  314.    bind(OUT,$outta) || die "bind: $!";
  315.  
  316.    $command[1]=$desthost if $nonint;
  317.    $command[2]=$destport if $nonint;
  318.           
  319.    if ((!($command[1])) or (!($command[2])) or $command[3]) {
  320.       print NS "bad params\n";
  321.       last DOOPEN;
  322.    }
  323.  
  324.    ($name,$aliases,$type,$len,$targetaddr)=gethostbyname($command[1]);
  325.       
  326.    $_=$command[2];
  327.  
  328.    if($_ !~ /^\d+$/) {
  329.      ($name, $aliases, $port) = getservbyname($command[2],'tcp');
  330.      print NS "bad port\n" if !($port);
  331.      last DOOPEN if !($port);
  332.      $command[2]=$port;
  333.    }
  334.    elsif ($command[2] > 65535) {
  335.       print NS "port > 65535? cool\n";
  336.       last DOOPEN;
  337.    }
  338.    $that=pack($sockaddr, $AF_INET, $command[2],$targetaddr);
  339.  
  340.    print NS "ok, connecting... \n" if !($nonint);
  341.    if (connect(OUT,$that)) {
  342.       print NS "ok, connected!\n" if !($nonint);
  343.       select(OUT); $|=1; select(STDOUT);
  344.       print OUT "$initstr\n" if ($nonint and $initstr);
  345.       if ($child_c=fork()){
  346.          while (read(OUT,$buf,1)) { print NS $buf;}         
  347.          sleep 3;
  348.          kill 9,$child_c if $child_c;
  349.       }
  350.       else { 
  351.          while (read(NS,$buffo,1)) { print OUT $buffo;}
  352.       }
  353.    }
  354.    else { print NS "error: $!\n"; }
  355.  }
  356. }
  357.